/*
 * This file is part of animus, a GUI for the command line app "GHost++"
 *
 * http://code.google.com/p/animus/
 *
 * Copyright (C) 2008-2009 Lucas Romero
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace animus
{
    public partial class FormEditTrigger : Form
    {
        public FormEditTrigger()
        {
            InitializeComponent();
            //dynamically load all trigger types available
            Assembly assembly = Assembly.GetAssembly(typeof(ConsoleTrigger));
            Type[] alltypes = assembly.GetTypes();
            foreach (Type t in alltypes)
            {
                if (t.IsSubclassOf(typeof(ConsoleTrigger)))
                {
                    cbTriggerType.Items.Add(assembly.CreateInstance(t.FullName));
                }
            }
            if (cbTriggerType.Items.Count>0)
                cbTriggerType.SelectedIndex = 0;
            else
            {
                MessageBox.Show("No triggers available!");
                DialogResult = DialogResult.Cancel;
                Close();
            }
        }

        public ConsoleTrigger ShowDialog(ConsoleTrigger oldTrigger)
        {
            if (oldTrigger != null)
            {
                ConsoleTrigger triggerCopy = (ConsoleTrigger)oldTrigger.Clone();
                cbTriggerType.Items.Clear();
                cbTriggerType.Items.Add(triggerCopy);
                cbTriggerType.SelectedIndex = 0;
                cbTriggerType.Enabled = false;
            }
            if (this.ShowDialog() == DialogResult.OK)
                return (ConsoleTrigger)cbTriggerType.SelectedItem;
            else
                return null;
        }

        private void cbTriggerType_SelectedValueChanged(object sender, EventArgs e)
        {
            pgTriggerProperties.SelectedObject = cbTriggerType.SelectedItem;
        }
    }
}